﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GrayParrot.RabbitMQ;
using Test.BLL;

namespace TestRabbitMQ
{
    public class RabbitMQSubscriber : Subscriber<RabbitMQSubscriber> 
    {
        UInt16 n = 0;

        public RabbitMQSubscriber()
            : base("GrayParrot-Test")
        {

        }

        public override bool Receive(byte[] message)
        {
            bool retValue = false;

            try
            {
                MessageBusBase<MessaggioTest> m_body = (MessageBusBase<MessaggioTest>)message.DeSerialize();

                Console.WriteLine(m_body.Body.Name);

                //Thread.Sleep(5000);  // wait 5 sec

                //throw new Exception("Prova di errore");

                //if (m_body.Body.Name.Contains('1'))
                //{
                //    retValue = true;
                //}

                retValue = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                retValue = false;
            }

            return retValue;
        }
    }
}
